package com.example.teesystem.controller;

import com.example.teesystem.common.Permission.PermissionCheck;
import com.example.teesystem.common.utils.PermissionUtil;
import com.example.teesystem.common.utils.Response;
import com.example.teesystem.common.utils.ResultCode;
import com.example.teesystem.entity.vo.exam.ExamUpdateVo;
import com.example.teesystem.entity.vo.examIssue.ExamIssueDeleteVo;
import com.example.teesystem.entity.vo.examIssue.ExamIssueInsertVo;
import com.example.teesystem.entity.vo.examIssue.ExamIssueUpdateVo;
import com.example.teesystem.entity.vo.examPaper.ExamPaperInstead;
import com.example.teesystem.service.ExamIssueService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

/**
 * @author : NieYaShi
 * @version : v1.0
 * @createTime : 2022/4/12 11:40
 */
@RestController
@RequestMapping(value = "/tee/examIssue" , produces = "application/json; charset=utf-8" )
@RequiredArgsConstructor
public class ExamIssueController {

    private final ExamIssueService examIssueService;

    /**
     * 添加试卷题目
     * @param examIssueInsertVo
     * @return
     */
    @PostMapping(value = "/addExamPaperIssue")
    @PermissionCheck(PermissionUtil.PAPER_PROVIDE)
    public Response addExamPaperIssue(@Valid @RequestBody ExamIssueInsertVo examIssueInsertVo){
        return examIssueService.addExamIssue(examIssueInsertVo);
    }

    @PostMapping(value = "/insteadExamPaperIssue")
    @PermissionCheck(PermissionUtil.PAPER_PROVIDE)
    public Response insteadExamPaperIssue(@Valid @RequestBody ExamPaperInstead examPaperInstead){
        return examIssueService.insteadIssueScore(examPaperInstead);
    }

    /**
     * 设置题目分数
     * @param examIssueUpdateVo
     * @return
     */
    @PostMapping(value = "/updateExamIssueScore")
    @PermissionCheck(PermissionUtil.PAPER_PROVIDE)
    public Response updateExamIssueScore(@Valid @RequestBody ExamIssueUpdateVo examIssueUpdateVo){
        return examIssueService.updateExamIssueScore(examIssueUpdateVo);
    }

    /**
     * 删除题目
     * @param examIssueDeleteVo
     * @return
     */
    @PostMapping(value = "/deleteExamIssues")
    @PermissionCheck(PermissionUtil.PAPER_PROVIDE)
    public Response deleteExamIssues(@Valid @RequestBody ExamIssueDeleteVo examIssueDeleteVo){
        return examIssueService.deleteExamIssues(examIssueDeleteVo);
    }

    /**
     * 获取未阅题目
     * @param map
     * @return
     */
    @PermissionCheck(PermissionUtil.PAPER_READ)
    @PostMapping(value = "/getNotMarkIssues")
    public Response getNotMarkIssues(@RequestBody Map<String, String> map){
        int paperId;
        int studentId;
        try{
            paperId = Integer.parseInt(map.get("paperId"));
            studentId = Integer.parseInt(map.get("studentId"));
        }catch (Exception e){
            return Response.error(ResultCode.PARAMETER_MISS.getMsg(), ResultCode.PARAMETER_MISS.getCode());
        }
        return examIssueService.getNotMarkIssue(paperId, studentId);
    }

    /**
     * 未阅试题评分
     * @param examUpdateVo
     * @return
     */
    @PostMapping(value = "/scoringNotMarkIssue")
    @PermissionCheck(PermissionUtil.PAPER_READ)
    public Response scoringNotMarkIssue(@Valid @RequestBody ExamUpdateVo examUpdateVo){
        return examIssueService.updateExamScore(examUpdateVo);
    }

}
